package com.sairobo.admin.modules.srblive.service.impl;

import java.util.Map;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.sairobo.base.common.entity.Page;
import com.sairobo.base.common.utils.CommonUtils;
import com.sairobo.admin.modules.srblive.service.SrbliveLiveroomtypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.sairobo.base.common.entity.Query;
import com.sairobo.base.common.entity.R;
import com.sairobo.admin.modules.srblive.entity.SrbliveLiveroomtype;
import com.sairobo.admin.modules.srblive.manager.SrbliveLiveroomtypeManager;

/**
 * 直播间类型
 *
 * @author admin
 * @email sairobo
 * @url www.sairobo.com
 * @date 2018年1月11日 下午8:04:39
 */
@Service("srbliveLiveroomtypeService")
public class SrbliveLiveroomtypeServiceImpl implements SrbliveLiveroomtypeService {

	@Autowired
	private SrbliveLiveroomtypeManager srbliveLiveroomtypeManager;

	@Override
	public Page<SrbliveLiveroomtype> listSrbliveLiveroomtype(Map<String, Object> params) {
		Query query = new Query(params);
		Page<SrbliveLiveroomtype> page = new Page<>(query);
		srbliveLiveroomtypeManager.listSrbliveLiveroomtype(page, query);
		return page;
	}

	@Override
	public R saveSrbliveLiveroomtype(SrbliveLiveroomtype role) {
		int count = srbliveLiveroomtypeManager.saveSrbliveLiveroomtype(role);
		return CommonUtils.msg(count);
	}

	@Override
	public R getSrbliveLiveroomtypeById(Long id) {
		SrbliveLiveroomtype srbliveLiveroomtype = srbliveLiveroomtypeManager.getSrbliveLiveroomtypeById(id);
		return CommonUtils.msg(srbliveLiveroomtype);
	}

	@Override
	public R updateSrbliveLiveroomtype(SrbliveLiveroomtype srbliveLiveroomtype) {
		int count = srbliveLiveroomtypeManager.updateSrbliveLiveroomtype(srbliveLiveroomtype);
		return CommonUtils.msg(count);
	}

	@Override
	public R batchRemove(Long[] id) {
		int count = srbliveLiveroomtypeManager.batchRemove(id);
		return CommonUtils.msg(id, count);
	}

    @Override
    public R getSonTypes(Long pid) {
        EntityWrapper<SrbliveLiveroomtype> ew = new EntityWrapper<>();
        ew.orderBy("id");
        if (null != pid) {
            ew.eq("parentId", pid);
        }
        return CommonUtils.msg(srbliveLiveroomtypeManager.selectList(ew));
    }
}
